<template>
  <div>
    <div class="container1">
      <div class="common-title-flex">
        <div class="common-title-div"></div>
        <div class="common-title-text">企业管理查询条件</div>
      </div>
      <el-form ref="searchObj" :inline="true" :model="searchObj" size="mini" label-width="80px" style="margin-bottom: -10px; margin-top: 10px">
        <el-form-item label="公司名称">
          <el-input v-model="searchObj.companyName" placeholder="请输入公司名称" clearable></el-input>
        </el-form-item>
        <el-form-item label="地址">
          <el-input v-model="searchObj.position" placeholder="请输入地址" clearable></el-input>
        </el-form-item>
        <el-form-item style="margin-left: 2rem">
          <el-button type="primary" icon="el-icon-search" @click="query">查询</el-button>
          <el-button @click="reset" icon="el-icon-refresh">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="container" style="margin-top: 1rem">
      <div class="common-list-class">
        <div style="display: flex">
          <div class="common-title-div"></div>
          <div class="common-title-text">企业管理查询列表</div>
        </div>
        <div style="display: flex">
          <el-upload v-if="roleCode == 'policeCommunity' || roleCode == 'policeGeneral'" class="upload-file" :headers="uploadHeader" :before-upload="beforeUpload" :action="uploadUrl" :on-success="uploadSucess" :on-error="uploadError" :show-file-list="false">
            <el-button type="primary" icon="el-icon-download">批量导入</el-button>
          </el-upload>
          <el-button type="primary" size="mini" v-if="roleCode == 'policeCommunity' || roleCode == 'policeGeneral'" style="height: 32px; margin-left: 10px" @click="allExportClick" icon="el-icon-position">下载模版</el-button>
          <el-button type="primary" style="height: 32px" v-if="roleCode == 'policeCommunity' || roleCode == 'policeGeneral'" icon="el-icon-circle-plus-outline" @click="addPolice">添加</el-button>
        </div>
      </div>
      <!-- 查询列表 -->
      <el-table :data="tableData" size="mini" :row-style="rowStyle" @sort-change="sortChange" @cell-click="cellChange" :header-cell-style="tableHeaderColor" style="width: 100%; margin-top: 10px; margin-bottom: 10px" max-height="550" border>
        <el-table-column prop="companyName" label="公司名称" show-overflow-tooltip align="center">
        </el-table-column>
        <el-table-column prop="orgCode" label="组织编码" show-overflow-tooltip align="center">
        </el-table-column>
        <el-table-column prop="companyAddr" label="地址" show-overflow-tooltip align="center">
        </el-table-column>
        <el-table-column prop="managerName" label="负责人" show-overflow-tooltip align="center">
        </el-table-column>
        <el-table-column prop="managerPhone" label="负责人电话" show-overflow-tooltip align="center">
        </el-table-column>
        <el-table-column prop="onlinePeopleNum" label="在职人数" sortable show-overflow-tooltip align="center">
          <template slot-scope="scope">
            <div style="cursor: pointer">
              {{ scope.row.onlinePeopleNum }}
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="status" label="状态" show-overflow-tooltip align="center">
          <template slot-scope="scope">
            {{ statusObj[scope.row.status] }}
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="350" align="center">
          <template slot-scope="scope">
            <!-- <el-button type="primary" size="mini" icon="el-icon-edit" @click="editClick(scope.row)">修改</el-button> -->
            <el-button type="primary" size="mini" icon="el-icon-tickets" @click="detailsClick(scope.row)">详情</el-button>
            <el-button type="success" size="mini" v-if="scope.row.status == 0 && typeCode == 'police'" icon="el-icon-video-play" @click="startClick(scope.row)">启动</el-button>
            <el-button type="danger" size="mini" v-if="scope.row.status == 1 && typeCode == 'police'" icon="el-icon-remove" @click="forbidClick(scope.row)">禁用</el-button>
            <el-button type="danger" size="mini" icon="el-icon-delete" v-if="typeCode == 'police'" @click="deleteClick(scope.row)">删除</el-button>
            <!-- <el-button type="warning" size="mini" icon="el-icon-share" @click="bindClick(scope.row)">绑定</el-button> -->
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-row type="flex" justify="end">
        <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage" :page-sizes="pageSizes" :page-size="pagesize" layout="total, sizes, prev, pager, next, jumper" :total="total">
        </el-pagination>
      </el-row>
    </div>

    <!-- 导入成功或失败列表 -->
    <el-dialog title="导入列表" :close-on-click-modal="false" :close-on-press-escape="false" :visible.sync="daoruFlag" width="80%" :before-close="daoruClose" center>
      <div slot="title" class="header-title">
        <div class="header-title-div"></div>
        <div class="header-title-text">导入列表</div>
      </div>
      <div class="common-title-flex">
        <div class="common-title-div"></div>
        <div class="common-title-text">导入成功列表</div>
      </div>
      <el-table :data="successList" size="mini" :row-style="rowStyle" :header-cell-style="tableHeaderColor" style="width: 100%; margin-top: 10px; margin-bottom: 10px" max-height="550" border>
        <el-table-column type="index" label="序号" width="50" align="center">
        </el-table-column>
        <el-table-column prop="companyName" label="公司名称" width="200" show-overflow-tooltip align="center">
        </el-table-column>
        <el-table-column prop="companyAddr" label="公司地址" width="200" show-overflow-tooltip align="center">
        </el-table-column>
        <el-table-column prop="managerName" label="负责人" width="100" show-overflow-tooltip align="center">
        </el-table-column>
        <el-table-column prop="managerPhone" label="负责人电话" width="100" show-overflow-tooltip align="center">
        </el-table-column>
        <el-table-column prop="girdName" label="所属网格" width="200" show-overflow-tooltip align="center">
        </el-table-column>
        <el-table-column prop="nature" label="企业性质" show-overflow-tooltip align="center">
          <template slot-scope="scope">
            {{ companyTypeListObj[scope.row.nature] }}
          </template>
        </el-table-column>
      </el-table>
      <div class="common-title-flex">
        <div class="common-title-div"></div>
        <div class="common-title-text">导入失败列表</div>
      </div>
      <el-table :data="failList" size="mini" :row-style="rowStyle" :header-cell-style="tableHeaderColor" style="width: 100%; margin-top: 10px; margin-bottom: 10px" max-height="550" border>
        <el-table-column type="index" label="序号" width="50" align="center" fixed="left">
        </el-table-column>
        <el-table-column prop="companyName" label="公司名称" width="200" align="center">
          <template slot-scope="scope">
            <el-input v-model="scope.row.companyName" placeholder="请输入公司名称" clearable></el-input>
          </template>
        </el-table-column>
        <el-table-column prop="managerName" label="负责人名称" width="200" align="center">
          <template slot-scope="scope">
            <el-input v-model="scope.row.managerName" placeholder="请输入负责人名称" clearable></el-input>
          </template>
        </el-table-column>
        <el-table-column prop="managerPhone" label="负责人电话" width="200" align="center">
          <template slot-scope="scope">
            <el-input v-model="scope.row.managerPhone" placeholder="请输入负责人电话" clearable></el-input>
          </template>
        </el-table-column>
        <el-table-column prop="companyAddr" label="公司地址" width="200" align="center">
          <template slot-scope="scope">
            <el-input v-model="scope.row.companyAddr" placeholder="请输入公司地址" clearable></el-input>
          </template>
        </el-table-column>
        <el-table-column prop="girdName" label="所属网格" width="200" align="center">
          <template slot-scope="scope">
            <el-input v-model="scope.row.girdName" placeholder="请输入所属网格"></el-input>
          </template>
        </el-table-column>
        <el-table-column prop="nature" label="企业性质" width="200" show-overflow-tooltip align="center">
          <template slot-scope="scope">
            <el-select v-model="scope.row.nature" placeholder="请选择企业性质" style="width: 100%">
              <el-option v-for="item in companyTypeList" :key="item.dictionaryCode" :label="item.dictionaryName" :value="item.dictionaryCode">
              </el-option>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column prop="errorMsg" label="失败原因" width="200" show-overflow-tooltip align="center">
          <!-- <template slot-scope="scope">
                        <div style="color:red;">{{scope.row.errorMsg}}</div>
                    </template> -->
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="200" align="center">
          <template slot-scope="scope">
            <el-button type="primary" size="mini" icon="el-icon-success" @click="confirmClick(scope.row)">确定</el-button>
            <el-button type="danger" size="mini" icon="el-icon-delete-solid" @click="deleteClick1(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" size="mini" :disabled="failList.length !== 0" @click="daoruClick">提交</el-button>
        <el-button size="mini" @click="daoruClose">关 闭</el-button>
      </span>
    </el-dialog>

    <!-- 新增警员 和修改警员-->
    <el-dialog :title="isEditTitle" :close-on-click-modal="false" :close-on-press-escape="false" :visible.sync="newaddFlag" width="50%" :before-close="handleClose" center>
      <div slot="title" class="header-title">
        <div class="header-title-div"></div>
        <div class="header-title-text">{{ isEditTitle }}</div>
      </div>
      <el-form ref="inputObj" :model="inputObj" label-width="120px" :rules="rules">
        <el-form-item label="公司名称" prop="companyName">
          <el-input v-model="inputObj.companyName" placeholder="请输入公司名称" clearable></el-input>
        </el-form-item>
        <el-form-item label="负责人" prop="managerName">
          <el-input v-model="inputObj.managerName" placeholder="请输入负责人" clearable></el-input>
        </el-form-item>
        <el-form-item label="负责人手机" prop="managerPhone">
          <el-input v-model="inputObj.managerPhone" placeholder="请输入负责人手机" clearable></el-input>
        </el-form-item>
        <el-form-item label="公司性质" prop="companyType">
          <el-select v-model="inputObj.companyType" placeholder="请选择公司性质" clearable style="width: 100%">
            <el-option v-for="item in companyTypeList" :key="item.dictionaryCode" :label="item.dictionaryName" :value="item.dictionaryCode">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="所属网格" prop="selfNetwork">
          <el-input v-model="inputObj.selfNetwork" placeholder="请输入所属网格" disabled></el-input>
        </el-form-item>
        <el-form-item label="匹配方式" prop="matchType">
          <el-select v-model="inputObj.matchType" placeholder="请选择匹配方式" clearable style="width: 100%">
            <el-option v-for="item in matchTypeList" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="地址" prop="JLBH" v-if="inputObj.matchType == '1'">
          <el-select v-model="inputObj.JLBH" placeholder="请选择地址" filterable clearable style="width: 100%">
            <el-option v-for="item in positionList" :key="item.jlbh" :label="item.companyAddr" :value="item.jlbh">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="地址" prop="position" v-if="inputObj.matchType == '0'">
          <el-input v-model="inputObj.position" placeholder="请输入地址" clearable></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button size="mini" type="primary" @click="submit">提 交</el-button>
        <el-button size="mini" @click="cancel">取 消</el-button>
      </span>
    </el-dialog>
    <!-- 警员详情 -->
    <el-dialog title="企业详情" :close-on-click-modal="false" :close-on-press-escape="false" :visible.sync="detailsFlag" width="40%" :before-close="detailsClose" center>
      <div slot="title" class="header-title">
        <div class="header-title-div"></div>
        <div class="header-title-text">企业详情</div>
      </div>
      <el-row type="flex" justify="center">
        <el-col :span="4" class="bold-class">公司名称</el-col>
        <el-col :span="15" class="grey-class">{{
          detailsObj.companyName
        }}</el-col>
      </el-row>
      <el-row type="flex" justify="center">
        <el-col :span="4" class="bold-class">组织编码</el-col>
        <el-col :span="15" class="grey-class">{{ detailsObj.orgCode }}</el-col>
      </el-row>
      <el-row type="flex" justify="center">
        <el-col :span="4" class="bold-class">负责人</el-col>
        <el-col :span="15" class="grey-class">{{
          detailsObj.managerName
        }}</el-col>
      </el-row>
      <el-row type="flex" justify="center">
        <el-col :span="4" class="bold-class">负责人手机</el-col>
        <el-col :span="15" class="grey-class">{{
          detailsObj.managerPhone
        }}</el-col>
      </el-row>
      <!-- <el-row type="flex" justify="center">
                <el-col :span="4" class="bold-class">公司性质</el-col>
                <el-col :span="15" class="grey-class">{{detailsObj.nature}}</el-col>
            </el-row> -->
      <el-row type="flex" justify="center">
        <el-col :span="4" class="bold-class">所属网格</el-col>
        <el-col :span="15" class="grey-class">{{
          detailsObj.girdCodeDesc
        }}</el-col>
      </el-row>
      <el-row type="flex" justify="center">
        <el-col :span="4" class="bold-class">在职人数</el-col>
        <el-col :span="15" class="grey-class">{{
          detailsObj.onlinePeopleNum
        }}</el-col>
      </el-row>
      <el-row type="flex" justify="center">
        <el-col :span="4" class="bold-class">地址</el-col>
        <el-col :span="15" class="grey-class">{{
          detailsObj.companyAddr
        }}</el-col>
      </el-row>
      <span slot="footer" class="dialog-footer">
        <el-button @click="detailsClose">关 闭</el-button>
      </span>
    </el-dialog>

    <!-- 警员详情 -->
    <el-dialog title="绑定劳务公司" :close-on-click-modal="false" :close-on-press-escape="false" :visible.sync="bindingFlag" width="40%" :before-close="bindingClose" center>
      <div slot="title" class="header-title">
        <div class="header-title-div"></div>
        <div class="header-title-text">绑定劳务公司</div>
      </div>
      <el-row type="flex" justify="center">
        <el-col :span="4">劳务公司</el-col>
        <el-col :span="15">
          <el-select v-model="bindObj.company" multiple placeholder="请选择劳务公司" clearable style="width: 100%">
            <el-option v-for="item in companyList" :key="item.dictionaryCode" :label="item.dictionaryName" :value="item.dictionaryCode">
            </el-option>
          </el-select>
        </el-col>
      </el-row>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="bindingSubmit">提 交</el-button>
        <el-button @click="bindingClose">关 闭</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import mixin from "@/mixin/mixin.js";
export default {
  name: "businessManage",
  mixins: [mixin],
  data() {
    return {
      companyList: [],
      bindingFlag: false,
      bindObj: {
        company: [],
      },
      daoruFlag: false,
      successList: [],
      failList: [],
      companyTypeList: [],
      matchTypeList: [
        {
          value: "0",
          label: "手动输入",
        },
        {
          value: "1",
          label: "选择输入",
        },
      ],
      positionList: [],
      statusObj: {
        0: "已停用",
        1: "已启用",
      },
      uploadHeader: {},
      uploadUrl: "/wgry/business/importedBusiness",
      rules: {
        companyName: [
          { required: true, message: "请输入公司名称", trigger: "blur" },
        ],
        companyType: [
          { required: true, message: "请选择行业类型", trigger: "change" },
        ],
        selfNetwork: [
          { required: true, message: "请输入所属网格", trigger: "blur" },
        ],
        position: [{ required: true, message: "请输入地址", trigger: "blur" }],
        JLBH: [{ required: true, message: "请选择地址", trigger: "change" }],
        matchType: [
          { required: true, message: "请选择匹配方式", trigger: "change" },
        ],
        managerPhone: [
          { required: true, message: "请输入负责人手机", trigger: "blur" },
          {
            validator: (rule, value, callback) => {
              // 手机正则校验
              if (!/^1[3456789]\d{9}$/.test(value.trim())) {
                callback(new Error("手机号码错误！"));
              } else {
                callback();
              }
            },
            trigger: "blur",
          },
        ],
        managerName: [
          { required: true, message: "请输入负责人姓名", trigger: "blur" },
        ],
      },
      detailsObj: {},
      inputObj: {
        companyName: "",
        companyType: "",
        selfNetwork: "",
        position: "",
      },
      detailsFlag: false,
      isEditTitle: "",
      newaddFlag: false,
      pageSizes: [10, 15, 50, 100],
      pagesize: 10,
      total: 10,
      currentPage: 1,
      tableData: [],
      currentId: "",
      searchObj: {
        companyName: "",
        position: "",
      },
      companyTypeListObj: {},
    };
  },
  created() {
    let obj = this.$route.params;
    console.log("obj----", obj);
    if (obj.labourName && obj.labourName.length) {
      this.searchObj.companyName = obj.labourName;
    }
    this.uploadHeader.Authorization = this.requestToken;
    this.queryPositionList();
    this.query();
  },
  methods: {
    sortChange({ column, prop, order }) {
      if (column.label == "在职人数") {
        if (order == "ascending") {
          console.log("正序");
          this.searchObj.peopleNumberStatus = 0;
          this.query();
        } else if (order == "descending") {
          this.searchObj.peopleNumberStatus = 1;
          this.query();
          console.log("倒序");
        }
      }
    },
    cellChange(row, column, cell, event) {
      if (column.label == "在职人数") {
        let val = row.companyName;
        let value = val.replace("（", "(").replace("）", ")");
        this.$router.push({
          name: "allPerson",
          params: { labourName: value, status: "在职人员" },
        });
      }
    },
    // 关闭
    daoruClose() {
      this.daoruFlag = false;
    },
    queryPositionList() {
      this.$axios({
        method: "get",
        url: `/business/queryMlp`,
        headers: {
          Authorization: this.requestToken,
        },
      })
        .then((res) => {
          if (res.data.code == "20000") {
            console.log(res.data.data);
            this.positionList = res.data.data;
          } else {
            this.$message({
              message: res.data.message,
              type: "error",
            });
          }
        })
        .catch((err) => {
          this.$message({
            message: err,
            type: "error",
          });
        });
    },
    queryAddInitInfo() {
      this.showLoading();
      this.$axios({
        method: "get",
        url: `/business/queryAddInitInfo`,
        headers: {
          Authorization: this.requestToken,
        },
      })
        .then((res) => {
          this.hideLoading();
          console.log("res---->:", res);
          if (res.data.code == "20000") {
            console.log(res.data.data);
            this.companyTypeList = res.data.data.natures;
            this.inputObj.selfNetwork = res.data.data.gridsDesc;
            this.inputObj.selfNetworkCode = res.data.data.grids;
            let obj = {};
            this.companyTypeList.forEach((item) => {
              obj[item.dictionaryCode] = item.dictionaryName;
            });
            this.companyTypeListObj = obj;
          } else {
            this.$message({
              message: res.data.message,
              type: "error",
            });
          }
        })
        .catch((err) => {
          this.hideLoading();
          this.$message({
            message: err,
            type: "error",
          });
        });
    },
    bindingSubmit() {
      if (!this.bindObj.company || !this.bindObj.company.length) {
        this.$message.error("请选择绑定劳务公司！");
        return;
      }
    },
    bindingClose() {
      this.bindingFlag = false;
      this.bindObj.company = [];
    },
    tableHeaderColor({ row, column, rowIndex, columnIndex }) {
      return "background-color:#f5f5f5;color:#626262;";
    },
    rowStyle({ row, rowIndex }) {
      let style1 = {};
      let style2 = {};
      if (rowIndex % 2 == 0) {
        style1.background = "#ffffff";
        return style1;
      } else {
        style2.background = "#f5f5f5";
        return style2;
      }
    },
    // 提交
    daoruClick() {
      let self = this;
      let params = self.successList;
      self.showLoading();
      self
        .$axios({
          method: "post",
          url: `/business/addOkBusinessInfos`,
          headers: {
            Authorization: self.requestToken,
          },
          data: params,
        })
        .then((res) => {
          self.hideLoading();
          if (res.data.code == "20000") {
            self.daoruFlag = false;
            self.$message({
              message: "提交成功！",
              type: "success",
            });
            self.query();
          } else {
            self.$message({
              message: res.data.message,
              type: "error",
            });
          }
        })
        .catch((err) => {
          self.hideLoading();
          self.$message({
            message: err,
            type: "error",
          });
        });
    },
    // 确认
    confirmClick(row) {
      let self = this;
      if (
        !row.companyName ||
        !row.managerName ||
        !row.managerPhone ||
        !row.companyAddr ||
        !row.girdName ||
        !row.nature
      ) {
        self.$message({
          message: "请输入必填字段再提交！",
          type: "error",
        });
        return;
      }
      let params = row;
      self.showLoading();
      self
        .$axios({
          method: "post",
          url: `/business/validateFailBusiness`,
          headers: {
            Authorization: self.requestToken,
          },
          data: params,
        })
        .then((res) => {
          self.hideLoading();
          if (res.data.code == "20000") {
            self.failList.forEach((item, index) => {
              if (item.id == row.id) {
                self.failList.splice(index, 1);
              }
            });
            self.successList.push(res.data.data);
            self.$message({
              message: "校验成功！",
              type: "success",
            });
          } else {
            self.$message({
              message: res.data.message,
              type: "error",
            });
          }
        })
        .catch((err) => {
          self.hideLoading();
          self.$message({
            message: err,
            type: "error",
          });
        });
    },
    bindClick(row) {
      this.bindingFlag = true;
      this.currentId = row.id;
    },
    // 删除
    deleteClick1(row) {
      let self = this;
      self.failList.forEach((item, index) => {
        if (item.id == row.id) {
          self.failList.splice(index, 1);
        }
      });
      self.$message({
        message: "删除成功！",
        type: "success",
      });
    },
    allExportClick() {
      let url = `${this.modelUrl}企业登记导入模板.xls`;
      window.open(url);
    },
    query() {
      let params = {
        companyName: this.searchObj.companyName,
        companyAddr: this.searchObj.position,
        pageNumber: this.currentPage,
        pageSize: this.pagesize,
      };
      this.showLoading();
      this.$axios({
        method: "post",
        url: `/business/queryList`,
        headers: {
          Authorization: this.requestToken,
        },
        data: params,
      })
        .then((res) => {
          this.hideLoading();
          console.log("res---->:", res);
          if (res.data.code == "20000") {
            this.tableData = res.data.data.list;
            this.pagesize = res.data.data.pageSize;
            this.total = res.data.data.total;
          } else {
            this.$message({
              message: res.data.message,
              type: "error",
            });
          }
        })
        .catch((err) => {
          this.hideLoading();
          this.$message({
            message: err,
            type: "error",
          });
        });
    },
    beforeUpload(file) {
      this.showLoading("导入中");
    },
    uploadSucess(response) {
      this.hideLoading();
      if (response.code == "20000") {
        this.daoruFlag = true;
        this.$message({
          message: "导入成功！",
          type: "success",
        });
        this.queryAddInitInfo();
        this.failList = response.data.failList;
        this.successList = response.data.list;
        console.log("response---->:", response);
      } else {
        this.$message({
          message: response.message,
          type: "error",
        });
      }
    },
    uploadError(error) {
      this.$message({
        message: "导入失败！",
        type: "error",
      });
      this.hideLoading();
      console.log("error-----", error);
    },
    // 新建确认和修改确认
    submit() {
      let self = this;
      this.$refs["inputObj"].validate((valid) => {
        if (valid) {
          if (self.isEditTitle == "新增企业") {
            let params = {
              companyName: self.inputObj.companyName,
              nature: self.inputObj.companyType,
              girdCode: self.inputObj.selfNetworkCode,
              companyAddr: self.inputObj.position,
              managerName: self.inputObj.managerName,
              managerPhone: self.inputObj.managerPhone,
            };
            if (self.inputObj.matchType == "0") {
              params.companyAddr = self.inputObj.position;
              params.mlp = "";
            } else {
              params.mlp = self.inputObj.JLBH;
              params.companyAddr = self.positionList.find(
                (val) => val.jlbh == self.inputObj.JLBH
              ).companyAddr;
            }
            self.showLoading();
            self
              .$axios({
                method: "post",
                url: `/business/addBusiness`,
                headers: {
                  Authorization: self.requestToken,
                },
                data: params,
                params: params,
              })
              .then((res) => {
                self.hideLoading();
                if (res.data.code == "20000") {
                  self.$message.success("新增成功！");
                  self.newaddFlag = false;
                  self.$refs["inputObj"].resetFields();
                  self.inputObj = {};

                  self.query();
                } else {
                  self.$message.error(res.data.message);
                }
              })
              .catch((err) => {
                self.hideLoading();
                self.$message.error(err);
              });
          } else {
          }
        } else {
          return false;
        }
      });
    },
    // 取消点击
    cancel() {
      this.newaddFlag = false;
      this.inputObj = {
        companyName: "",
        companyType: "",
        selfNetwork: "",
        position: "",
        managerPhone: "",
        managerName: "",
      };
      this.$refs["inputObj"].resetFields();
    },
    // 取消点击
    handleClose() {
      this.cancel();
    },
    // 点击分页当前页多少数据
    handleSizeChange(val) {
      this.pagesize = val;
      this.query();
    },
    // 点击分页页数
    handleCurrentChange(val) {
      this.currentPage = val;
      this.query();
    },
    //  重置
    reset() {
      this.searchObj = {
        companyName: "",
        industyType: "",
        relationMan: "",
      };
      this.query();
    },
    // 删除
    deleteClick(row) {
      this.$confirm("请确认是否删除该企业?", "删除", {
        confirmButtonText: "是",
        cancelButtonText: "否",
      })
        .then(() => {
          this.showLoading();
          this.$axios({
            method: "delete",
            url: `/business/deleteById/${row.id}`,
            headers: {
              Authorization: this.requestToken,
            },
          })
            .then((res) => {
              this.hideLoading();
              if (res.data.code == "20000") {
                this.$message.success("删除成功！");
                this.query();
              } else {
                this.$message.error(res.data.message);
              }
            })
            .catch((err) => {
              this.hideLoading();
              this.$message.error(err);
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    startClick(row) {
      this.$confirm("请确认是否启用该企业?", "启用", {
        confirmButtonText: "是",
        cancelButtonText: "否",
      })
        .then(() => {
          this.showLoading();
          this.$axios({
            method: "get",
            url: `/business/editOpenStatus/${row.id}/1`,
            headers: {
              Authorization: this.requestToken,
            },
          })
            .then((res) => {
              this.hideLoading();
              if (res.data.code == "20000") {
                this.$message.success("启用成功！");
                this.query();
              } else {
                this.$message.error(res.data.message);
              }
            })
            .catch((err) => {
              this.hideLoading();
              this.$message.error(err);
            });
        })
        .catch(() => {});
    },
    // 禁用
    forbidClick(row) {
      let self = this;
      this.$confirm("请确认是否禁用该企业?", "禁用", {
        confirmButtonText: "是",
        cancelButtonText: "否",
      })
        .then(() => {
          self.showLoading();
          self
            .$axios({
              method: "get",
              url: `/business/editOpenStatus/${row.id}/0`,
              headers: {
                Authorization: self.requestToken,
              },
            })
            .then((res) => {
              self.hideLoading();
              if (res.data.code == "20000") {
                self.$message.success("禁用成功！");
                self.query();
              } else {
                self.$message.error(res.data.message);
              }
            })
            .catch((err) => {
              self.hideLoading();
              self.$message.error(err);
            });
        })
        .catch(() => {});
    },
    // 新增
    addPolice() {
      this.newaddFlag = true;
      this.queryAddInitInfo();
      this.isEditTitle = "新增企业";
      this.inputObj.matchType == "1";
    },
    // 详情
    detailsClick(row) {
      let self = this;
      self.showLoading();
      self
        .$axios({
          method: "get",
          url: `/business/queryInfoByid/${row.id}`,
          headers: {
            Authorization: self.requestToken,
          },
        })
        .then((res) => {
          self.hideLoading();
          if (res.data.code == "20000") {
            self.detailsFlag = true;
            self.detailsObj = res.data.data;
          } else {
            self.$message.error(res.data.message);
          }
        })
        .catch((err) => {
          self.hideLoading();
          self.$message.error(err);
        });
    },
    // 详情关闭
    detailsClose() {
      this.detailsFlag = false;
    },
    // 修改
    editClick(row) {
      let self = this;
      self.isEditTitle = "修改企业";
      self.showLoading();
      self
        .$axios({
          method: "get",
          url: `/business/queryInfoByid/${row.id}`,
          headers: {
            Authorization: self.requestToken,
          },
        })
        .then((res) => {
          self.hideLoading();
          if (res.data.code == "20000") {
            let datalist = res.data.data;
            self.newaddFlag = true;
          } else {
            self.$message.error(res.data.message);
          }
        })
        .catch((err) => {
          self.hideLoading();
          self.$message.error(err);
        });
    },
  },
};
</script>
<style scoped>
.common-title-flex {
  display: flex;
}
.common-title-div {
  width: 3px;
  height: 16px;
  background-color: #368af7;
  margin-top: 2px;
}
.common-title-text {
  margin-left: 4px;
  font-size: 14px;
}
.common-list-class {
  display: flex;
  justify-content: space-between;
  margin-top: -10px;
}
.upload-file >>> .el-upload--text {
  border: none;
  width: 100px;
  height: 36px;
}
</style>>